package com.young.interceptor;

import com.young.config.SysConfig;
import com.young.entity.User;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * 描述:拦截没有完善资料的用户，跳转到修改资料页
 *
 * @author BluceYoung
 * @create 2020-12-06 14:09
 * B站：TeacherYoung凌风
 * www.teacheryoung.com
 */
public class CompleteInfoInterceptor extends HandlerInterceptorAdapter {

    /**
     * This implementation always returns {@code true}.
     *
     * @param request
     * @param response
     * @param handler
     */
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        User user =(User) request.getSession().getAttribute(SysConfig.SESSION_USER);
        //如果有用户信息，并且昵称为null，说明没有完善个人资料
        if(user!=null && user.getNickName()==null){
            response.sendRedirect(request.getContextPath()+"/user/edit.html");
            return false;//拦截
        }
        return true;
    }
}
